import axios from "axios";
import { fromJS } from "_immutable@4.0.0-rc.12@immutable";
import { constants } from "./index"
const getAllDataAction  = ( { topicList, articleList, recommendList }) => ({
        type: constants.GET_ALL_DATA,
        topicList,
        articleList,
        recommendList
})
export const getAllData=() => {
    return dispatch => {
        axios.get("/api/home.json").then((res) => {
            dispatch(getAllDataAction(res.data.data));
        })
    }
}
const addHomeList = (res, nextPage) => ({
    type: constants.ADD_HOME_LIST,
    list: fromJS(res),
    nextPage
})
export const getMoreList = (page) => {
    return dispatch => {
        axios.get("/api/homeList.json?page="+page).then(res=>{
            console.log(res);
            dispatch(addHomeList(res.data.data,page+1))
        })
    }
}

export const toggleToShow = (show) => {
    return {
        type: constants.TOGGLE_SHOW,
        show
    }
}